package com.goods.business.service.imp;

import com.goods.business.mapper.ConsumerMapper;
import com.goods.business.service.ConsumerService;
import com.goods.common.model.business.Consumer;
import com.goods.common.vo.business.ConsumerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ConsumerServiceImpl implements ConsumerService {


    @Autowired
    private ConsumerMapper consumerMapper;

    @Override
    public List<ConsumerVO> findConsumerList(String address, String contact, String name) {
       return consumerMapper.selectExt(address,contact,name);
    }

    @Override
    public void add(Consumer consumer) {
        consumer.setCreateTime(new Date());
        consumer.setModifiedTime(new Date());
        consumerMapper.insert(consumer);
    }

    @Override
    public Consumer edit(Long id) {
        return consumerMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(Long id,Consumer consumer) {
        consumer.setId(id);
        consumerMapper.updateByPrimaryKeySelective(consumer);
    }

    @Override
    public void delete(Long id) {
        consumerMapper.deleteByPrimaryKey(id);
    }


    /*@Override
    public PageVO<ConsumerVO> findConsumerList(Integer pageNum, Integer pageSize, ConsumerVO consumerVO) {
        PageHelper.startPage(pageNum,pageSize);
        Example o = new Example(Supplier.class);
        String address = consumerVO.getAddress();    //省市区
        String name = consumerVO.getName();         //具体地址
        String contact = consumerVO.getContact();       //联系人
        Example.Criteria criteria = o.createCriteria();
        if (address != null && !"".equals(address)){
            criteria.andLike("address","%"+address+"%");
        }
        if (name != null && !"".equals(name)){
            criteria.andLike("name","%"+name+"%");
        }
        if (contact != null && !"".equals(contact)){
            criteria.andLike("contact","%"+contact+"%");
        }
        List<Consumer> consumerList = consumerMapper.selectByExample(o);
        List<ConsumerVO> consumerVOS = new ArrayList<>();
        if(!CollectionUtils.isEmpty(consumerList)){
            for (Consumer c : consumerList) {
                ConsumerVO s = new ConsumerVO();
                BeanUtils.copyProperties(c,s);
                consumerVOS.add(s);
            }
        }
        PageInfo<Consumer> info = new PageInfo<>(consumerList);
        return new PageVO<>(info.getTotal(), consumerVOS);
    }*/

}
